﻿
/**
* Copyright (c) 2011
* All rights reserved.
* @author Khurram Ali khan <khurram_khan123@hotmail.com>
* @version 1.0.1
*/

/* @group Common Functions
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/
function Seperator(limitField) {
    var RegExSeperator = /([A-Za-z0-9.]+)/g;
    var strSeperator = limitField.value;
    if (!strSeperator.match(RegExSeperator)) {
        limitField.value = limitField.value.substring(0, (limitField.value.length - 1));
    }
}

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
}

function ValidateListBox(listBox) {
    if ($("." + listBox).val()) {
        return true;
    }
    else {
        alert('Select at least one value');
    }
    return false;
}
// Replaces all instances of the given substring.
String.prototype.replaceAll = function (
	strTarget, // The substring you want to replace
	strSubString // The string you want to replace in.
	) {
    var strText = this;
    var intIndexOfMatch = strText.indexOf(strTarget);

    // Keep looping while an instance of the target string
    // still exists in the string.
    while (intIndexOfMatch != -1) {
        // Replace out the current instance.
        strText = strText.replace(strTarget, strSubString)

        // Get the index of any next matching substring.
        intIndexOfMatch = strText.indexOf(strTarget);
    }

    // Return the updated string with ALL the target strings
    // replaced out with the new substring.
    return (strText);
}

//Adjustment Number Fields
function AdjustmentNumField(limitField, isPaste) {
    var RegExSeperator = /^(\d|-)?(\d|,)*\.?\d*$/gm;
    var strSeperator = limitField.value;

    if (!strSeperator.match(RegExSeperator)) {
        if (!isPaste) {
            limitField.value = limitField.value.substring(0, (limitField.value.length - 1));
        } else {
            limitField.value = '';
        }
    }

}

function onClick(id, msg) {
    if (id.value == msg) {
        id.value = '';
    }
}

function onBlur(id, msg) {
    if (id.value == '') {
        id.value = msg;
    }
}
/* @group End
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/

/* @group Global Variables
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/
var isFormValid = false;

//Array for getting the objects of all the validates 
var formArray = [];
var formMessageArray = [];
var strMessage = '';
var msgMain = 0;
var msgSub = 0;
var messageArray = [];
var functionNameArray = [];

var IsSyncRunning = false;

// arrays use for adjustment validation
var revisedArray = [];
var commentArray = [];

var intervalID;

/* @group End
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/

/* @group Dom Initialization
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/
jQuery(function ($) {

    // add confirm box div on the page
    AddConfirmBoxOnPage();

    //Internalization Validation
    IntionalizationValidation();

    //For Adding satiric on the mandatory fields
    AddStaric();

    //body overlay
    BodyOverlay();

    //Call SideBar Height Adjustment function
    sideBar();

    //Call Show Hide box
    showHide();

    //Hide green messages from the list page after 30 second    
    setTimeout(FadeOutGreenMessage, 3000);

    //Reminder Window
    //    Reminderdailog();

    //Date time picker initialize
    applyDatePicker();
});

/* @group Adjust Side Bar Height
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/
function sideBar() {
    var sidebar = $('#sidebar')
    var content = $('#content')
    if (sidebar.length > 0 && content.length > 0) {
        var sidebarHeight = sidebar.height();
        var contentHeight = content.height();
        if (contentHeight > sidebarHeight) {
            sidebar.css('min-height', contentHeight);
        }
    }
}
/* @group End
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/

/* @group Show Hide Box By expend and collapse
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/
function showHide() {
    var showHide = $('.showHide');
    var showHideText = $('<span class="expandClass">Collapse</span>');
    if (showHide.length) {
        var panel = $('#panel');
        showHideText.bind('click', function () {
            var elem = $(this);
            panel.slideToggle('slow', function () {
                if (elem.text() == 'Collapse')
                    elem.text('Expand');
                else
                    elem.text('Collapse');
            });
        });
        showHide.after(showHideText);
    }
}
/* @group End
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/

/* @group Confirmation Box
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/
function AddConfirmBoxOnPage() {
    if ($('.confirm').length > 0) {
        var confirmBoxHtml = "<div id='confirm'><div class='header'><span id='txtTitle'>Confirm</span></div><div class='message'></div><div class='buttons'><div id='txtCancelButton' class='no simplemodal-close'>No</div><div id='txtOKButton' class='yes'>yes</div></div></div>";
        $(confirmBoxHtml).appendTo('body');
    }
}
function ConfirmEvent(txtMessage, contorlID, txtBoxTitle, txtPostbackButtonText, txtNotPostbackButtonText, isPostbackButtonShow, isNotPostbackButtonShow) {

    var postbackText = (txtPostbackButtonText == null) ? 'Yes' : txtPostbackButtonText;
    var notPostbackText = (txtNotPostbackButtonText == null) ? 'No' : txtNotPostbackButtonText;
    var titleText = (txtNotPostbackButtonText == null) ? 'Confirm' : txtBoxTitle;

    $('#txtOKButton').text(postbackText).hide();
    $('#txtCancelButton').text(notPostbackText).hide();
    $('#txtTitle').text(titleText);

    if (isPostbackButtonShow) {
        $('#txtOKButton').show();
    }

    if (isNotPostbackButtonShow) {
        $('#txtCancelButton').show();
    }

    var isValid = false;

    // you must use a callback function to perform the "yes" action
    confirm(txtMessage, function (e) {
        if (typeof (contorlID) == 'object')
            __doPostBack(contorlID.name, "OnClick");
        else
            __doPostBack(contorlID, "OnClick");
    });

    return isValid;
}

//function confirm(message, callback) {

//    $('#confirm').modal({
//        closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
//        position: ["20%", ],
//        overlayId: 'confirm-overlay',
//        containerId: 'confirm-container',
//        onShow: function (dialog) {
//            $('.message', dialog.data[0]).append(message);

//            // if the user clicks "yes"
//            $('.yes', dialog.data[0]).click(function () {
//                // call the callback
//                if ($.isFunction(callback)) {
//                    callback.apply();
//                }
//                // close the dialog
//                $.modal.close();
//            });
//        }
//    });
//}
/* @group End
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/

/* @group Date Picker
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/
function applyDatePicker() {

    $("input.DatePicker").each(function () {
        var $me = $(this);

        var _currYear = new Date();
        _currYear = _currYear.getFullYear();

        var _option = {};

        var _setting = {
            changeYear: true,
            dateFormat: 'dd-M-yy',
            dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
        };

        if ($me.hasClass('DateRange')) {
            _option = {
                minDate: '0y 0m 0d',
                maxDate: '0y 0m 365d',
                yearRange: (_currYear) + ':' + (_currYear + 1)
            };
        }

        _setting = $.extend(_setting, _option);

        $($me).datepicker(_setting);
    });
    $("input.DatePicker").bind('paste', function () { return false; });
    $("input.DatePicker").bind('cut', function () { return false; });
    $("input.DatePicker").bind('keydown', function () { limitText($(this).get(0), 0); });
    $("input.DatePicker").bind('keyup', function () { limitText($(this).get(0), 0); });
}
/* @group End
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/

/* @group Validation for fields
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/
function IntionalizationValidation() {
    var isFormValid = false;
    FillArray(formArray, formMessageArray);
    $('.SubmitButton').click(function (e) {
        var tempArray = [];
        messageArray = [];
        //alert(e.currentTarget.getAttribute("ValidationGroupss"));
        var ValidationGroup = e.currentTarget.getAttribute("ValidationGroupss");
        msgMain = msgSub = 0;
        var isValidationGroup = false;
        if (ValidationGroup != undefined && ValidationGroup != "")
            isValidationGroup = true;
        for (var i = 0; i < formArray.length; i++) {
            var domElement = formArray[i];
            if (isValidationGroup == true) {

                if (domElement.attr("ValidationGroupss") != undefined && domElement.attr("ValidationGroupss") == ValidationGroup)
                    if (domElement.attr('disabled') === false) {
                        var isReadonly = domElement.attr('readonly');
                        if (isReadonly === false || isReadonly === undefined) {
                            if (!OnSubmitClick(domElement, i)) {
                                tempArray.push(false);
                            } else {
                                tempArray.push(true);
                            }
                        }
                    }
            }
            else {
                if (domElement.attr("ValidationGroupss") == undefined || domElement.attr("ValidationGroupss") == "")
                    if (domElement.attr('disabled') === false) {
                        var isReadonly = domElement.attr('readonly');
                        if (isReadonly === false || isReadonly === undefined) {
                            if (!OnSubmitClick(domElement, i)) {
                                tempArray.push(false);
                            } else {
                                tempArray.push(true);
                            }
                        }

                    }
            }
        }
        isFormValid = ValidateIt(tempArray);

        if (isFormValid) {
            isFormValid = InitiateRunAlertBox($(this), isFormValid);
        }
        return isFormValid;
    });
}


function ValidateIt(tempArray) {
    var isValid = false;
    var msgString = '';
    var tempString = '';

    if (msgMain > 0) {
        msgString = 'Fields marked * are mandatory.<br />Kindly fill in the mandatory fields, highlighted in red color.';
    }
    for (var x = 0; x < tempArray.length; x++) {
        if (tempArray[x] == false) {
            if (messageArray.length > 0) {
                for (var t = 0; t < messageArray.length; t++) {
                    tempString += '<br />' + messageArray[t];
                }
                if (msgSub > 0) {
                    msgString += tempString;
                }
                if (msgMain === 0) {
                    msgString = msgString.substr(6, msgString.length);
                }
            }
            if ($('.ServerErrorMsg').length) {
                $('.ServerErrorMsg').hide();
            }
            $('#ErrorMsg').html(msgString);
            $(".Warning").fadeOut();
            $('.Warning').fadeIn();
            $('.Warning').focus();
            isValid = false;
            break;
        } else {
            isValid = true;
            $(".Warning").fadeOut();
        }
    }
    return isValid;
}


function ApplyClasses(label, field) {
    field.addClass('redBdr');
    label.addClass('redCol');
}


function RemoveClasses(label, field) {
    field.removeClass('redBdr');
    label.removeClass('redCol');
}


function FillArray(fieldArray, labelArray) {
    $('.Validate').each(function (index) {
        fieldArray.push($(this));
    });

    $('.FormLabel').each(function (index) {
        labelArray.push($(this));
    });
}

function OnSubmitClick(elem, index) {
    var isValid = false;
    var fieldValue = elem.val();
    if (!elem.hasClass('IsNullable')) {
        if (jQuery.trim(fieldValue) == '') {
            ApplyClasses(formMessageArray[index], elem);
            msgMain += 1;
            isValid = false;
        } else {
            RemoveClasses(formMessageArray[index], elem);
            isValid = true;
            isValid = AllValidatePattern(elem, formMessageArray[index], isValid, false);
        }
    }
    else {
        isValid = AllValidatePattern(elem, formMessageArray[index], isValid, true);
    }
    if (elem.hasClass('Select')) {
        if (fieldValue == '-1') {
            ApplyClasses(formMessageArray[index], elem.parent());
            msgMain += 1;
            isValid = false;
        } else {
            RemoveClasses(formMessageArray[index], elem.parent());
            isValid = true;
        }
    }
    if (elem.hasClass('Accept')) {
        if (elem.attr('checked')) {
            RemoveClasses(formMessageArray[index], elem);
            isValid = true;
        }
        else {
            ApplyClasses(formMessageArray[index], elem);
            msgMain += 1;
            isValid = false;
        }
    }
    return isValid;
}

function AllValidatePattern(elem, label, isValid, isNullAllow) {
    isValid = ValidateEmailAddressWithNullable(elem, label, isValid, isNullAllow);
    isValid = ValidateDateWithNullable(elem, label, isValid, isNullAllow);
    isValid = ValidateNICWithNullable(elem, label, isValid, isNullAllow);
    isValid = ValidateCustomFunctionWithNullable(elem, label, isValid, isNullAllow);
    isValid = ValidateNumberWithNullable(elem, label, isValid, isNullAllow);
    isValid = ValidateURLWithNullable(elem, label, isValid, isNullAllow);

    return isValid;
}

function ValidateEmailAddressWithNullable(elem, label, isValid, isNullAllow) {
    if (isNullAllow) {
        if (elem.val() == '') {
            RemoveClasses(label, elem);
            isValid = true;
        }
        else {
            isValid = ValidateEmailAddress(elem, label, isValid);
        }
    }
    else {
        isValid = ValidateEmailAddress(elem, label, isValid);
    }
    return isValid;
}

function ValidateNumberWithNullable(elem, label, isValid, isNullAllow) {
    if (isNullAllow) {
        if (elem.val() == '') {
            RemoveClasses(label, elem);
            isValid = true;
        }
        else {
            isValid = ValidateNumber(elem, label, isValid);
        }
    }
    else {
        isValid = ValidateNumber(elem, label, isValid);
    }
    return isValid;
}
function ValidateURLWithNullable(elem, label, isValid, isNullAllow) {
    if (isNullAllow) {
        if (elem.val() == '') {
            RemoveClasses(label, elem);
            isValid = true;
        }
        else {
            isValid = ValidateUrl(elem, label, isValid);
        }
    }
    else {
        isValid = ValidateUrl(elem, label, isValid);
    }
    return isValid;
}

function ValidateUrl(elem, label, isValid) {
    var fieldValue = elem.val();
    if (elem.hasClass('Url')) {
        var numberRegEx = /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/;
        if (fieldValue.match(numberRegEx)) {
            RemoveClasses(label, elem);
            isValid = true;
        }
        else {
            msgSub += 1;
            messageArray.push(label.text() + ' Please Enter The Valid URL');
            ApplyClasses(label, elem);
            isValid = false;
        }
    }
    return isValid;
}

function ValidateEmailAddress(elem, label, isValid) {
    var fieldValue = elem.val();
    if (elem.hasClass('Email')) {
        var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+[a-zA-Z0-9]{2,4}$/;
        if (fieldValue.match(emailRegEx)) {
            RemoveClasses(label, elem);
            isValid = true;
        }
        else {
            msgSub += 1;
            messageArray.push(label.text() + ' Please Enter The Valid Email Address');
            ApplyClasses(label, elem);
            isValid = false;
        }
    }
    return isValid;
}
function ValidateNumber(elem, label, isValid) {
    var fieldValue = elem.val();
    if (elem.hasClass('Number')) {
        var numberRegEx = /^[\-\+]?\d+$/;
        if (fieldValue.match(numberRegEx)) {
            RemoveClasses(label, elem);
            isValid = true;
        }
        else {
            msgSub += 1;
            messageArray.push(label.text() + ' Please Enter The Valid number');
            ApplyClasses(label, elem);
            isValid = false;
        }
    }
    return isValid;
}

function ValidateDateWithNullable(elem, label, isValid, isNullAllow) {
    if (isNullAllow) {
        if (elem.val() == '') {
            RemoveClasses(label, elem);
            isValid = true;
        }
        else {
            isValid = ValidateDate(elem, label, isValid);
        }
    }
    else {
        isValid = ValidateDate(elem, label, isValid);
    }
    return isValid;
}

function ValidateDate(elem, label, isValid) {
    var fieldValue = elem.val();
    if (elem.hasClass('ValidateDate')) {
        //var dateRegEx = /(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d/g;
        var dateRegEx = /(0[1-9]|[12][0-9]|3[01])[-](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[-](19|20)\d\d/g;
        if (fieldValue.match(dateRegEx)) {
            var dateParts = fieldValue.split("/");
            var parseDate = new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]);
            RemoveClasses(label, elem);
            isValid = true;
        }
        else {
            msgSub += 1;
            messageArray.push(label.text().replaceAll(':*', '') + ' Please Enter the Valid Date Format e.g. DD-MMM-YYYY');
            ApplyClasses(label, elem);
            isValid = false;
        }
    }
    return isValid;
}

function ValidateNICWithNullable(elem, label, isValid, isNullAllow) {
    if (isNullAllow) {
        if (elem.val() == '') {
            RemoveClasses(label, elem);
            isValid = true;
        }
        else {
            isValid = ValidateNIC(elem, label, isValid);
        }
    }
    else {
        isValid = ValidateNIC(elem, label, isValid);
    }
    return isValid;
}

function ValidateNIC(elem, label, isValid) {
    var fieldValue = elem.val();
    if (elem.hasClass('ValidateNIC')) {
        var dateRegEx = /(\d{5})-(\d{7})-(\d{1})/g;
        if (fieldValue.match(dateRegEx)) {
            RemoveClasses(label, elem);
            isValid = true;
        }
        else {
            msgSub += 1;
            messageArray.push(label.text() + ' Please Enter the Valid NIC Number e.g. 12345-1234567-1');
            ApplyClasses(label, elem);
            isValid = false;
        }
    }
    return isValid;
}

function ValidateCustomFunctionWithNullable(elem, label, isValid, isNullAllow) {
    if (isNullAllow) {
        if (elem.val() == '') {
            RemoveClasses(label, elem);
            isValid = true;
        }
        else {
            isValid = ValidateCustomFunction(elem, label, isValid);
        }
    }
    else {
        isValid = ValidateCustomFunction(elem, label, isValid);
    }
    return isValid;
}
function ValidateCustomFunction(elem, label, isValid) {
    if (elem.hasClass('CustomFunction')) {
        var functionName = elem.attr('FunctionName');
        var fn = window[functionName];
        if (typeof (fn) === 'function') {
            var strMsg = fn(elem, label);
            if (strMsg != undefined) {
                isValid = false;
                msgSub += 1;
                messageArray.push(strMsg);
            } else {
                isValid = true;
            }
        }

    }
    return isValid;
}
function InitiateRunAlertBox(elem, isFormValid) {
    if ($('.ShowAlertBox').length > 0)
        isFormValid = ConfirmEvent('Are you sure you want to cancel the changes?', elem.attr('name'), '<Payroll Name>', 'Yes', 'No', true, true);
    else {
        var ov = $('#Overlay');

        ov.height($('body').height());
        ov.show();
    }
    return isFormValid;
}
/* @group End
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/

function DateFunctionFrom(elem, label) {

    return DateFunction(elem, $('.SecondDateField'), label, $('.SecondDateLabel'), false);
}

function DateFunctionTo(elem, label) {

    return DateFunction(elem, $('.FirstDateField'), label, $('.FirstDateLabel'), true);
}

function DateFunction(firstElement, secondElement, firstLabel, secondLabel, isFromField) {

    var firstElementValue = firstElement.val();
    var secondElementValue = secondElement.val();
    var strMsg;

    var dateRegEx = /(0[1-9]|[12][0-9]|3[01])[-](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[-](19|20)\d\d/g;

    if ($.trim(firstElementValue) !== '' && !firstElementValue.match(dateRegEx)) {
        firstElement.addClass('redBdr');
        firstLabel.addClass('redCol');
        strMsg = firstLabel.text().replaceAll('*', '') + ' Please Enter the Valid Date Format DD-MMM-YYYY';
        return strMsg;
    } else {
        firstElement.removeClass('redBdr');
        firstLabel.removeClass('redCol');
    }

    if ($.trim(firstElementValue) !== '' && $.trim(secondElementValue) === '') {

        firstElement.removeClass('redBdr');
        firstLabel.removeClass('redCol');
        secondElement.addClass('redBdr');
        secondLabel.addClass('redCol');
        strMsg = secondLabel.text().replaceAll('*', '') + ' Field must be required';
        return strMsg;
    }

    if (isFromField) {
        if ($.trim(firstElementValue) !== '' && $.trim(secondElementValue) !== '') {
            var vDate = ParseDate(firstElementValue);
            var pDate = ParseDate(secondElementValue);
            if (pDate > vDate) {
                strMsg = secondLabel.text() + ' should be less than ' + firstLabel.text();
                strMsg = strMsg.replaceAll(':*', '');
                return strMsg;
            } else {
            }
        }
    }
    return strMsg;
}

function ParseDate(d) {
    var dateParts = d.split("-");
    return new Date(dateParts[1] + ' ' + dateParts[0] + ',' + dateParts[2]);
}

function EmailAssinged() {
    var $hdEmailBox = $('#hfEmailAddress');
    var $lblEmailBox = $('#lblEmailAddress');
    if ($lblEmailBox.length != 0)
        $lblEmailBox[0].innerHTML = $hdEmailBox.val();
}

function AssignValue(elem, label) {
    var hiddenValue = $('#lstAssigned')
    var strMsg;
    if (hiddenValue === '0' || hiddenValue === '') {
        strMsg = "You should assigned roles to user."
        ApplyClasses(label, elem);
    } else {
        RemoveClasses(label, elem);
    }
    return strMsg;
}
/* @group End
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/

/* @group add * for all mandatory fields
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/
function AddStaric() {
    $('.FormLabel').each(function () {
        var me = $(this);
        if (!me.hasClass('isNotMandatory')) {
            me.append('<em>*</em>');
        }
    });
}
/* @group End
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/
function CheckEntetEvent() {
    return false;
}
/* @group overlay show while post back the page
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/
function BodyOverlay() {
    var overlay = $('.IsOverlay');
    var ov = $('#Overlay');

    if (ov.is(":visible")) {
        ov.hide()
    }
    if (overlay.length) {
        overlay.click(function () {
            //alert($('body').height() + ' - ' + $('html').height())
            ov.height($('body').height());
            //console.log('chal raha ha mer bhai');
            ov.show();
        });
    }
}
/* @group End
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/

/* @group End fade out the green messges from list page 
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––------------------------*/
function FadeOutGreenMessage() {
    var jqObject = $('.green-color-box');
    if (jqObject.length) {
        jqObject.fadeOut(function () {
            $(this).remove();
        });
    }
}
function applyDatePicker() {
    $("input.DatePicker").each(function () {
        var $me = $(this);
        var _currYear = new Date();
        _currYear = _currYear.getFullYear();
        var _option = {};
        var _setting = {
            changeYear: true,
            dateFormat: 'dd-M-yy',
            dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
        };
        if ($me.hasClass('DateRange')) {
            _option = {
                minDate: '0y 0m 0d',
                maxDate: '0y 0m 365d',
                yearRange: (_currYear) + ':' + (_currYear + 1)
            };
        }
        _setting = $.extend(_setting, _option);
        $($me).datepicker(_setting);
    });
}

function applyFocusAndBlurEffects() {
    // bind focus and blur events of textboxes
    $(".formContainer input:text, .formContainer input:password, .formContainer select")
		.focus(function () { $(this).addClass('focus'); })
		.blur(function () { $(this).removeClass('focus'); });
}

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
}

$(function () {
    applyDatePicker();

    // bind the close event of notifier message
    $('.notify-close a').bind('click', function () { notifier.hide(); });

    applyFocusAndBlurEffects();

    $("input.DatePicker").bind('paste', function () { return false; });
    $("input.DatePicker").bind('cut', function () { return false; });
    $("input.DatePicker").bind('keydown', function () { limitText($(this).get(0), 0); });
    $("input.DatePicker").bind('keyup', function () { limitText($(this).get(0), 0); });


    checkReminders();
});

function checkReminders() {
    setInterval(function () {
        if (config != undefined) {
            var handlerPath = config.appPath + "/Handlers/GetRemindersCount.ashx";
            $.get(handlerPath, function (count) {
                if (count > 0) {
                    $('#reminder_dialog').dialog('open');
                }
            });
        }

    }, 1000 * 60);
}

//Report screen
function switchViews(obj, row) {
    var div = document.getElementById(obj);
    var img = document.getElementById('img' + obj);

    if (div.style.display == "none") {
        div.style.display = "inline";
        img.src = "../images/plus.png";
    } else {
        div.style.display = "none";
        img.src = "../images/rminus.gif";
    }
}